package com.yhm.testSpringMvc.Thread;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolSimpleDemo {
    public static void main(String[] args) {

        ExecutorService executorService  = Executors.newFixedThreadPool(3);
        executorService.execute(new yhmThreadPoolSimpleDemo1());
        executorService.execute(new yhmThreadPoolSimpleDemo2());
        executorService.execute(new yhmThreadPoolSimpleDemo3());
        executorService.execute(new yhmThreadPoolSimpleDemo4());
        executorService.execute(new yhmThreadPoolSimpleDemo5());
        executorService.execute(new yhmThreadPoolSimpleDemo6());
        executorService.execute(new yhmThreadPoolSimpleDemo7());

        executorService.shutdown();
        System.out.println("主线程执行完毕");

    }

    static class yhmThreadPoolSimpleDemo1 implements Runnable {

        @Override
        public void run() {
            System.out.println("do somethings: yhmThreadPoolSimpleDemo1");
            try {
                Thread.sleep(new Random().nextInt(9999));
                //做其他事情
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    static class yhmThreadPoolSimpleDemo2 implements Runnable {

        @Override
        public void run() {
            System.out.println("do somethings: yhmThreadPoolSimpleDemo2");
            try {
                Thread.sleep(new Random().nextInt(9999));
                //做其他事情
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    static class yhmThreadPoolSimpleDemo3 implements Runnable {

        @Override
        public void run() {
            System.out.println("do somethings: yhmThreadPoolSimpleDemo3");
            try {
                Thread.sleep(new Random().nextInt(9999));
                //做其他事情
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
    static class yhmThreadPoolSimpleDemo4 implements Runnable {

        @Override
        public void run() {
            System.out.println("do somethings: yhmThreadPoolSimpleDemo4");
            try {
                Thread.sleep(new Random().nextInt(9999));
                //做其他事情
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    static class yhmThreadPoolSimpleDemo5 implements Runnable {

        @Override
        public void run() {
            System.out.println("do somethings: yhmThreadPoolSimpleDemo5");
            try {
                Thread.sleep(new Random().nextInt(9999));
                //做其他事情
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
    static class yhmThreadPoolSimpleDemo6 implements Runnable {

        @Override
        public void run() {
            System.out.println("do somethings: yhmThreadPoolSimpleDemo6");
            try {
                Thread.sleep(new Random().nextInt(9999));
                //做其他事情
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    static class yhmThreadPoolSimpleDemo7 implements Runnable {

        @Override
        public void run() {
            System.out.println("do somethings: yhmThreadPoolSimpleDemo7");
            try {
                Thread.sleep(new Random().nextInt(9999));
                //做其他事情
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
